package myStudent

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/api/myStudents/programs/\\d+')),
                producer('/api/myStudents/programs/1'))
        headers {
            contentType(applicationJsonUtf8())
            header("id", 1)
        }
    }
    response {
        status 200
        body("""
          [{
                "sumPoints": 0,
                "student": {
                    "id": 2,
                    "username": "hh",
                    "password": "",
                    "email": "1025383143@qq.com",
                    "mobilePhone": "18829290322",

                    "roles": [
                        2
                    ]
                }
            }]
        """)
        bodyMatchers {
            jsonPath('$.[*]', byType())
            jsonPath('$.[*].sumPoints', byRegex(number()))
            jsonPath('$.[*].student.username', byRegex(nonEmpty()))
            jsonPath('$.[*].student.id', byRegex(number()))
            jsonPath('$.[*].student.email', byRegex(email()))
        }
        headers {
            contentType(applicationJsonUtf8())
        }

    }
}